package com.nari.system.controller;

import com.nari.common.core.utils.poi.ExcelUtil;
import com.nari.common.core.web.controller.BaseController;
import com.nari.common.core.web.domain.AjaxResult;
import com.nari.common.core.web.page.TableDataInfo;
import com.nari.common.log.annotation.Log;
import com.nari.common.log.enums.BusinessType;
import com.nari.common.security.annotation.PreAuthorize;
import com.nari.system.api.domain.SysRstLog;
import com.nari.system.service.ISysRstLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 报文日志记录
 * 
 * @author quanss
 */
@RestController
@RequestMapping("/rstlog")
public class SysRstlogController extends BaseController
{
    @Autowired
    private ISysRstLogService rstLogService;

    @PreAuthorize(hasPermi = "system:rstlog:list")
    @GetMapping("/list")
    public TableDataInfo list(SysRstLog rstLog)
    {
        startPage();
        List<SysRstLog> list = rstLogService.selectRstLogList(rstLog);
        return getDataTable(list);
    }

    @Log(title = "报文日志", businessType = BusinessType.EXPORT)
    @PreAuthorize(hasPermi = "system:rstlog:export")
    @PostMapping("/rstexport")
    public void export(HttpServletResponse response, SysRstLog rstLog) throws IOException
    {
        List<SysRstLog> list = rstLogService.selectRstLogList(rstLog);
        ExcelUtil<SysRstLog> util = new ExcelUtil<SysRstLog>(SysRstLog.class);
        util.exportExcel(response, list, "操作日志");
    }

    @PreAuthorize(hasPermi = "system:rstlog:remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rstLogService.deleteRstLogByIds(ids));
    }

    @PreAuthorize(hasPermi = "system:rstlog:remove")
    @Log(title = "报文日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public AjaxResult clean()
    {
        rstLogService.cleanRstLog();
        return AjaxResult.success();
    }

    @PostMapping
    public AjaxResult add(@RequestBody SysRstLog rstLog)
    {
        return toAjax(rstLogService.insertRstlog(rstLog));
    }
}
